package hn.cch.spring_boot_webapps_war;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class ServletInitializer extends SpringBootServletInitializer {

    private static Logger logger = LoggerFactory.getLogger(ServletInitializer.class);


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        logger.info("configure sources");
        // 两种方式都可以
        // Properties properties = new Properties();
        // try {
        //     String home = System.getProperty("catalina.home");
        //     String path = home + File.separator + "application.properties";
        //     File file = new File(path);
        //     if (file.exists()) {
        //         properties.load(new FileInputStream(file));
        //         System.getProperties().putAll(properties);
        //         logger.info("file.path:{}", path);
        //     } else {
        //         logger.error("application.properties is not exist");
        //     }
        //
        // } catch (Exception e) {
        //     logger.error(e.getMessage());
        // }
        return application.sources(SpringBootWebappsWarApplication.class);
    }

}
